import { connect } from 'react-redux';
import CountUi from '../../components/countUi/CountUI';
import { handleadd, handledecrement, handleasync } from '../../redux/actions';

/* 
react-redux有一个connect函数
connect(mapstateToProps,mapDispatchToProps)(UI组件)
mapstateToProps 映射状态 返回值是一个对象
mapDispatchToProps 操作状态的方法 返回值是一个对象

*/
const mapStateToProps = (state) => {
    return {
        count: state
    }
}
const mapDispatchToProps = (dispatch) => {
    return {
        add: num => dispatch(handleadd(num)),
        decrement: num => dispatch(handledecrement(num)),
        tasync: num => dispatch(handleasync(num))
    }
}


// connect()() 创建并暴露一个Count的容器组件
export default connect(mapStateToProps, mapDispatchToProps)(CountUi);